# 画t分布单侧检验示意图
rm(list = ls())
library(ggplot2)

dt_limit <- function(x){
  y <- dt(x, df = 25)
  y[x < qt(0.95, df = 25)] <- NA
  return(y)
}

p <- ggplot(data.frame(x = c(-4,4)), aes(x = x))
p + stat_function(fun = dt_limit, geom = 'area', fill = 'blue', alpha = 0.2) +
  stat_function(fun = dt, args = list(df = 25)) +
  annotate('segment', x = 2.5, xend = 1.9, y = 0.1, yend = 0.03, arrow = arrow(length = unit(3,'mm')))+
  annotate('text', x = 2.5, y = 0.12, label = '面积=0.05', size = 8) +
  scale_x_continuous(breaks = qt(0.95,25)) +
  theme_bw(base_family = 'STKaiti') +
  theme(axis.text.x = element_text(size = 20))
ggsave('../fig42.pdf', device = cairo_pdf, family = 'STKaiti')
